package com.future.direction.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.direction.R;
import com.future.direction.di.component.AppComponent;
import com.future.direction.ui.widget.MyTitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by XWL on 2020/2/11.
 * Description: 验证码登录
 */

public class VerificationCodeLoginActivity extends BaseActivity implements View.OnClickListener {


    @BindView(R.id.titleBar)
    MyTitleBar titleBar;
    @BindView(R.id.et_phone_num)
    EditText etPhoneNum;
    @BindView(R.id.iv_edit_clear)
    ImageView ivEditClear;
    @BindView(R.id.et_verification_code)
    EditText etVerificationCode;
    @BindView(R.id.tv_get_verification_code)
    TextView tvGetVerificationCode;
    @BindView(R.id.tv_login)
    TextView tvLogin;
    @BindView(R.id.view_phone_num)
    View viewPhoneNum;
    @BindView(R.id.view_verification_code)
    View viewVerificationCode;

    @Override
    public int setLayout() {
        return R.layout.activity_verification_code_login;
    }

    @Override
    public void getExtras() {

    }

    @Override
    public boolean init() {
        return false;
    }

    @Override
    public void setListener() {
        backListener(titleBar);
        etPhoneNum.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    viewPhoneNum.setBackgroundColor(getResources().getColor(R.color.colorBlue0D7EF9));
                }else {
                    viewPhoneNum.setBackgroundColor(getResources().getColor(R.color.colorBlackDCE2E8));
                }
            }
        });
        etVerificationCode.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    viewVerificationCode.setBackgroundColor(getResources().getColor(R.color.colorBlue0D7EF9));
                }else {
                    viewVerificationCode.setBackgroundColor(getResources().getColor(R.color.colorBlackDCE2E8));
                }
            }
        });
        //手机号输入监听
        etPhoneNum.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.toString().length() >= 1) {
                    ivEditClear.setVisibility(View.VISIBLE);
                } else {
                    ivEditClear.setVisibility(View.GONE);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        ivEditClear.setOnClickListener(this);
        tvGetVerificationCode.setOnClickListener(this);
        tvLogin.setOnClickListener(this);

    }

    @Override
    public void setupAcitivtyComponent(AppComponent appComponent) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //清空输入的手机号
            case R.id.iv_edit_clear:
                etPhoneNum.setText("");
                break;
            //获取验证码
            case R.id.tv_get_verification_code:

                break;
            //登录
            case R.id.tv_login:
                tologin();
                break;
        }
    }

    private void tologin() {
//        if (etPhoneNum.getText().toString().length()<11) {
//            ToastUtils.shortShow("请输入完整的11位手机号");
//            return;
//        }
//        if (etVerificationCode.getText().toString().length()<4){
//            ToastUtils.shortShow("请输入完整的4位验证码");
//            return;
//        }
        Intent intent = new Intent(this, ReferralCodeActivity.class);
        startActivity(intent);
    }


}
